<template>
	<view class="">
		<view :style="{height:windowHeight}" style="padding-left: 32rpx;padding-right: 32rpx;" v-if="workTeamList.length>0">
			<view v-for="(item,index) in workTeamList" :key="index" 
			@click="clickTap(item)" @longpress="longpress(item)">
				<view class="item">
					<view style="display: flex;align-items: center;">
						<image src="../../../../../static/pc_customer.png" style="width: 48rpx;height: 48rpx;"></image>
						<text class="item_title">{{item.name}}</text>
					</view>
					<view class="item_content">
						{{item.realName}}
					</view>
				</view>
			</view>
		</view>
		
		<view :style="{height:windowHeight}" v-if="workTeamList.length==0"
			style="display: flex;align-items: center;justify-content: center;">
			<view>
				<view style="display: flex;align-items: center;justify-content: center;">
					<image :src="no_data" style="width: 300rpx;height: 300rpx;"></image>
				</view>
				<view style="display: flex;align-items: center;justify-content: center;">
					<text style="font-weight: 400;color: #333333;font-size: 28rpx;">暂无数据</text>
				</view>
			</view>
		</view>
		
		<view class="view-bottom">
			<view class="view-bottom-s">
				<view class="view-bottom-sl" @click="add">
					新增
				</view>
			</view>
			<!-- <view style="height: 68rpx;background: #ffffff;" v-if="needAdapt"> -->
				<!-- 苹果x及以上的安全距离 -->
			<!-- </view> -->
			
		</view>
		
		<view class="zhezhao" v-if="isShowTips">
			<view class="zhezhao-view-bottom">
				<view class="zhezhao-view-bottom-s" @click="clickTap(1)">
					编辑
				</view>
				<view class="zhezhao-view-bottom-s" @click="clickTap(2)">
					删除
				</view>
				<view class="zhezhao-view-bottom-s" @click="clickTap(3)">
					取消
				</view>
			</view>
		</view>
		
	</view>
</template>

<script>
	let app = ''
	export default{
		data(){
			return{
				roleUrl:'',
				windowHeight:0,
				needAdapt: false, //判断是不是苹果x以上机型
				workTeamList:[],
				role:'',
				caseId:'',
				
				isShowTips:false,
				item:null,
				no_data:getApp().globalData.baseImageUrl+'/no-data.png',
			}
		},
		onLoad() {
			app = getApp()
			var _this = this

			_this.needAdapt = app.globalData.needAdapt && app.globalData.isIPhone
			_this.role = app.globalData.role
			_this.roleUrl =  _this.$roleUrl({tab:_this.role})
			if(_this.needAdapt){
				_this.windowHeight = (app.globalData.windowHeight -88)*2 + 'rpx'
			}else{
				_this.windowHeight = (app.globalData.windowHeight -54)*2 + 'rpx'
			}
			
		},
		onShow() {
			this.getList()
		},
		mounted() {
			
		},
		methods:{
			async getList(){
				let _this = this
				let url = ''
			
				const res = await _this.$myRequest({
					url: `/${_this.roleUrl}/workGroup/list`,
					data:{
						page:1,
						size:1000
					},
					method:'POST',//默认是GET
				})
				console.log('工作组',res)
				if(res.data.code==200){
					let list =  res.data.data.list
					for (var i = 0; i < list.length; i++) {
						let nameArray = list[i]['users']
						let realName = ''
						for (var j = 0; j < nameArray.length; j++) {
							realName = realName+' '+nameArray[j]['account']['realName']
						}
						list[i]['realName'] = realName
					}
					_this.workTeamList = res.data.data.list
				}
				
			},
			add(){
				uni.navigateTo({
					url:'./addWorkTeam?'+'&tag=add'
				})
			},
			
			/**
			 * 长按
			 */
			longpress(val){
				console.log('长按',val)
				this.item = val
				this.isShowTips = true
			},
			/**
			 * 点击
			 */
			clickTap(val){
				this.isShowTips = false
				console.log('点击',val)
				if(val==1){
					//编辑
					let users = this.item.users
					for (var i = 0; i < users.length; i++) {
						users[i]['remark'] = ''
					}
					this.item.users = users
					let item = JSON.stringify(this.item)
				
					uni.navigateTo({
						url:'./addWorkTeam?'+'&tag=edit&item='+item
					})
				}else  if(val==2){
					//删除
					this.deleteIt()
				}else if(val==3){
					//取消
					this.item = null
				}else{
					//编辑
					let users = val.users
					for (var i = 0; i < users.length; i++) {
						users[i]['remark'] = ''
					}
					val.users = users
					
					let item = JSON.stringify(val)
					uni.navigateTo({
						url:'./addWorkTeam?'+'&tag=edit&item='+item
					})
				}
			},
			/**
			 * 删除
			 */
			async deleteIt(){
				let _this = this
				uni.showLoading({
					title:'正在删除...'
				})
				const res = await _this.$myRequest({
					url: `/${_this.roleUrl}/workGroup`,
					data: {
						ids:_this.item.id
					},
					method: 'DELETE', //默认是GET
				})
				uni.hideLoading()
				if(res.data.code==200){
					uni.showToast({
						title:'删除成功!',
						icon:"success"
					})
					_this.workTeamList = []
					_this.getList()
				}
			},
		}
	}
</script>

<style>
	page{
		background-color: #ffffff;
	}
</style>
<style scoped lang="scss">
	.view-bottom{
		position: fixed;
		width: 100%;
		bottom: 0;
		background-color: #ffffff;
		border-top: 1rpx solid #e1e1e1;
		padding-bottom: env(safe-area-inset-bottom); 
	}
	.view-bottom-s{
		height: 108rpx;
		display: flex;
		align-items: center;
	}
	.view-bottom-sl{
		width: 686rpx;
		height: 88rpx;
		background: #2DA9C5;
		border-radius: 58rpx;
		margin-left: 32rpx;
		font-size: 36rpx;
		font-family: PingFangSC-Medium, PingFang SC;
		font-weight: 500;
		color: #E8F7FB;
		display: flex;
		align-items: center;
		justify-content: center;

	}
	
	.item{
		height: 172rpx;
		border-bottom: 1rpx solid #EEEEEE;
		padding-top: 32rpx;
		
	}
	.item_title{
		margin-left: 12rpx;
		font-size: 28rpx;
		font-family: PingFangSC-Semibold, PingFang SC;
		font-weight: 600;
		color: #333333;
	}
	.item_content{
		margin-top: 24rpx;
		margin-left: 60rpx;
		font-size: 28rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #333333;
	}
	
	.zhezhao {
		width: 100%;
		height: 100vh;
		background: rgba(0, 0, 0, 0.4);
		z-index: 9999;
		position: fixed;
		left: 0;
		top: 0;
		overflow: scroll;	
		// padding-top: 10vh;
		display: flex;
		align-items: center;
		justify-content: center;
	}
	.zhezhao-view-bottom{
		position: fixed;
		width: 100%;
		bottom: 0;
		background-color: #ffffff;
		border-top-right-radius: 16rpx;
		border-top-left-radius: 16rpx;
		padding-bottom: env(safe-area-inset-bottom); // 适配iphoneX的底部
	}
	.zhezhao-view-bottom-s{
		height:88rpx;
		border-bottom: 1rpx #eeeeee solid;
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 28rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
	
	}
</style>